# -*- coding: utf-8 -*-
"""
Created on Thu Jul  1 16:33:32 2021

@author: chentao
"""

from pyfirmata import Arduino

board=Arduino('com1')

LB_IN1=2
LB_IN2=4
#LB_EN=3

LU_IN1=6
LU_IN2=7
#LU_EN=5

RU_IN1=8
RU_IN2=9
#RU_EN=10

RB_IN1=12
RB_IN2=14
#RB_EN=11

LB_EN=board.get_pin('d:3:p')
LU_EN=board.get_pin('d:5:p')
RU_EN=board.get_pin('d:10:p')
RB_EN=board.get_pin('d:11:p')
RB_IN2=board.get_pin('a:A0:p')
#150映射为0.6

def Up(): 
    LB_EN.write(0.6)
    LU_EN.write(0.6)
    RU_EN.write(0.6)
    RB_EN.write(0.6)
    board.digital[LB_IN1].write(0)
    board.digital[LB_IN2].write(1)
    board.digital[LU_IN1].write(0)
    board.digital[LU_IN2].write(1)
    board.digital[RB_IN1].write(0)
    board.digital[RB_IN2].write(1)
    RB_IN2.write(1)
    board.digital[RU_IN1].write(0)
    board.digital[RU_IN2].write(1)
    

def Back():
    
    board.digital[LB_IN1].write(1)
    board.digital[LB_IN2].write(0)
    board.digital[LU_IN1].write(1)
    board.digital[LU_IN2].write(0)
    board.digital[RB_IN1].write(1)
    board.digital[RB_IN2].write(0)
    board.digital[RU_IN1].write(1)
    board.digital[RU_IN2].write(0)
    LB_EN.write(0.6)
    LU_EN.write(0.6)
    RU_EN.write(0.6)
    RB_EN.write(0.6)




def TurnRight():
    #左侧正转右侧反转
    
    board.digital[LB_IN1].write(0)
    board.digital[LB_IN2].write(1)
    board.digital[LU_IN1].write(0)
    board.digital[LU_IN2].write(1)
    board.digital[RB_IN1].write(1)
    board.digital[RB_IN2].write(0)
    board.digital[RU_IN1].write(1)
    board.digital[RU_IN2].write(0)
    LB_EN.write(0.6)
    LU_EN.write(0.6)
    RU_EN.write(0.6)
    RB_EN.write(0.6)



#ba
#ab

#LU RU
#LB RB
def TurnLeft():
    #左侧反转右侧正转
    board.digital[LB_IN1].write(1)
    board.digital[LB_IN2].write(0)
    board.digital[LU_IN1].write(1)
    board.digital[LU_IN2].write(0)
    board.digital[RB_IN1].write(0)
    board.digital[RB_IN2].write(1)
    board.digital[RU_IN1].write(0)
    board.digital[RU_IN2].write(1)
    LB_EN.write(0.6)
    LU_EN.write(0.6)
    RU_EN.write(0.6)
    RB_EN.write(0.6)



def RightLine():
    #a反转b正转
    
    board.digital[LB_IN1].write(1)
    board.digital[LB_IN2].write(0)
    board.digital[LU_IN1].write(0)
    board.digital[LU_IN2].write(1)
    board.digital[RB_IN1].write(0)
    board.digital[RB_IN2].write(1)
    board.digital[RU_IN1].write(1)
    board.digital[RU_IN2].write(0)
    LB_EN.write(0.6)
    LU_EN.write(0.6)
    RU_EN.write(0.6)
    RB_EN.write(0.6)



def LeftLine():
    #a正转b反转
    
    board.digital[LB_IN1].write(0)
    board.digital[LB_IN2].write(1)
    board.digital[LU_IN1].write(1)
    board.digital[LU_IN2].write(0)
    board.digital[RB_IN1].write(1)
    board.digital[RB_IN2].write(0)
    board.digital[RU_IN1].write(0)
    board.digital[RU_IN2].write(1)
    LB_EN.write(0.6)
    LU_EN.write(0.6)
    RU_EN.write(0.6)
    RB_EN.write(0.6)



def Stop():
    
    board.digital[LB_IN1].write(0)
    board.digital[LB_IN2].write(0)
    board.digital[LU_IN1].write(0)
    board.digital[LU_IN2].write(0)
    board.digital[RB_IN1].write(0)
    board.digital[RB_IN2].write(0)
    board.digital[RU_IN1].write(0)
    board.digital[RU_IN2].write(0)
    LB_EN.write(0.6)
    LU_EN.write(0.6)
    RU_EN.write(0.6)
    RB_EN.write(0.6)



Up()
#Back()
#TurnRight()
# TurnLeft()
# RightLine()
# LeftLine()
# Stop()

